import React,{Component} from "react"
import {mediator} from './mediator'

interface IProps {
    authKey:string
}
interface IStates {
    authList:string[],
    show:boolean
}

export default class Power extends Component<IProps,IStates>{
    constructor(props:IProps){
        super(props)
        this.state = {
            show:false,
            authList:[]
        }
    }
    public componentDidMount() {
        this.setState({authList:mediator.getUserBtn("getUserBtn")},() => {
            // console.log(this.state.authList)
            this.state.authList.forEach((item:string) => {
                if(item === this.props.authKey){
                    this.setState({show:true})
                }
            })
        })
    }
    public render() {
        const {show} = this.state
        if(show){
            return (
                <React.Fragment>
                    {this.props.children}
                </React.Fragment>
            )
        }else {
            return null
        }
    }
}